function minEatingSpeed(piles: number[], h: number): number {
  let l = 1;
  let r = Math.max(...piles);

  const can = (mid) => {
    const sum = piles.reduce((a, b) => {
      a += Math.ceil(b / mid);
      return a;
    }, 0);

    return sum <= h;
  };

  while (l < r) {
    const mid = (l + r) >> 1;

    if (can(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }

  return l;
}
